package com.Sdebruijn.curriculumvitae.models;

import android.os.Parcel;
import android.os.Parcelable;

import com.google.gson.annotations.SerializedName;
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;

/**
 * Wrapper for a {@link Person}'s online activities
 * 
 * @author Stefan de Bruijn
 */
@DatabaseTable(tableName = "OnlinePerson")
public class OnlinePerson implements Parcelable {

	OnlinePerson() {
		// all persisted classes must define a no-arg constructor with at least
		// package visibility
	}

	/**
	 * Auto-incremented id for the ORMLite-SQLite database
	 */
	@DatabaseField(generatedId = true)
	private int id;

	/**
	 * Public LinkedIn profile id
	 */
	@DatabaseField
	@SerializedName("linkedin_id")
	public String linkedin_id;

	/**
	 * A link to a public LinkedIn profile
	 */
	@DatabaseField
	@SerializedName("linkedin_url")
	public String linkedin_url;

	/**
	 * Public Google+ profile id
	 */
	@DatabaseField
	@SerializedName("google_plus_id")
	public String google_plus_id; // ID is to big for Integer and Long

	/**
	 * A link to a public Google+ profile
	 */
	@DatabaseField
	@SerializedName("google_plus_url")
	public String google_plus_url;

	/**
	 * A link to a public Facebook profile or username
	 */
	@DatabaseField
	@SerializedName("facebook")
	public String facebook; // TODO ORMLite/Gson can't handle URL?

	/**
	 * A link to a public Twitter profile or username
	 */
	@DatabaseField
	@SerializedName("twitter")
	public String twitter; // TODO ORMLite/Gson can't handle URL?

	/**
	 * A link to a public Google Project Hosting profile hosting open source
	 * projects
	 */
	@DatabaseField
	@SerializedName("google_project_hosting")
	public String google_project_hosting; // TODO ORMLite/Gson can't handle URL?

	/**
	 * A link to a public Google Project Hosting profile hosting open source
	 * projects
	 */
	@DatabaseField
	@SerializedName("stackoverflow")
	public String stackoverflow; // TODO ORMLite/Gson can't handle URL?

	/*
	 * Required methods to have this class as Parcelable Having this class
	 * Parcelable will make it easier to restore it into fragments with
	 * savedInstanceState
	 */

	/*
	 * Just used as id - hashCode() will do fine
	 * 
	 * @see android.os.Parcelable#describeContents()
	 */
	@Override
	public int describeContents() {
		return this.hashCode();
	}

	/*
	 * Serialize my object attributes one by one
	 * 
	 * @see android.os.Parcelable#writeToParcel(android.os.Parcel, int)
	 */
	@Override
	public void writeToParcel(Parcel parcel, int flags) {
		parcel.writeInt(this.id);
		parcel.writeString(this.facebook);
		parcel.writeString(this.google_plus_id);
		parcel.writeString(this.google_plus_url);
		parcel.writeString(this.linkedin_id);
		parcel.writeString(this.linkedin_url);
		parcel.writeString(this.twitter);
		parcel.writeString(this.google_project_hosting);
		parcel.writeString(this.stackoverflow);

	}

	/**
	 * Required for any Parcelable class to be recreated. Will be called to
	 * de-serialize the object.
	 * 
	 * @author Stefan de Bruijn
	 * 
	 */
	public static final Parcelable.Creator<OnlinePerson> CREATOR = new Parcelable.Creator<OnlinePerson>() {
		public OnlinePerson createFromParcel(Parcel source) {
			return new OnlinePerson(source);
		}

		public OnlinePerson[] newArray(int size) {
			return new OnlinePerson[size];
		}
	};

	/**
	 * <b>Do not use!</b> Private constructor for the Parcelable Creator. Will
	 * de-serialize the object.
	 * 
	 * @param source
	 */
	private OnlinePerson(Parcel source) {
		this.id = source.readInt();
		this.facebook = source.readString();
		this.google_plus_id = source.readString();
		this.google_plus_url = source.readString();
		this.google_project_hosting = source.readString();
		this.linkedin_id = source.readString();
		this.linkedin_url = source.readString();
		this.twitter = source.readString();
		this.stackoverflow = source.readString();

	}
}
